package models

import "time"

type PayOrder struct {
	ID           int64     `gorm:"column:id" json:"id"`
	OrderId      string    `gorm:"column:order_id" json:"order_id"`
	MemberId     int64     `gorm:"column:member_id" json:"member_id"`
	ProductType  int64     `gorm:"column:product_type" json:"product_type"`
	Amount       int64     `gorm:"column:amount" json:"amount"`
	Added        int64     `gorm:"column:added" json:"added"`
	PayId        string    `gorm:"column:pay_id" json:"pay_id"`
	Status       int64     `gorm:"column:status" json:"status"`
	PayType      int64     `gorm:"column:pay_type" json:"pay_type"`
	Remarks      string    `gorm:"column:remarks" json:"remarks"`
	CreateTime   time.Time `gorm:"column:create_time" json:"create_time"`
	UpdateTime   time.Time `gorm:"column:update_time" json:"update_time"`
	Balance      int64     `gorm:"column:balance" json:"balance"`
	Mcoin        int64     `gorm:"column:mcoin" json:"mcoin"`
	RefundAmount int64     `gorm:"column:refund_amount" json:"refund_amount"`
	AllAmount    int64     `gorm:"column:all_amount" json:"all_amount"`
}

func (this *PayOrder) GetListByMemberID(
	where map[string]interface{},
	pagination map[string]interface{},
) (
	payOrders []PayOrder,
	count int,
) {
	if _, ok := pagination["status"]; !ok {
		pagination["status"] = []int{1}
	}
	db := Db
	db = ParsePagination(db, pagination)
	db = ParseWhere(db, where)
	db.
		Table("pay_order").
		Count(&count).
		Scan(&payOrders)
	return
}

func (this *PayOrder) GetById(payOrderID int, MemberId int) *PayOrder {
	db := Db
	db.Table("pay_order").
		Where("id = ?", payOrderID).
		Where("member_id = ? ", MemberId).
		Scan(this)
	return this
}
